import Vue from 'vue'
import App from './App.vue'
import router from './router'
import 'lib-flexible'
import Vant from 'vant'
import 'vant/lib/index.css'
import 'xgplayer/dist/index.min.css'
import store from './store'
import SvgIcon from '@/components/SvgIcon'
import { sync } from 'vuex-router-sync'
import { getCookieToken } from '@/utils/auth'

import DetailHeader from '@/components/DetailHeader'
Vue.component('detail-header', DetailHeader)
import MineHeader from '@/components/MineHeader'
Vue.component('MineHeader', MineHeader)

import { Lazyload } from 'vant'
Vue.use(Lazyload)

/* import native from '@/utils/native'
Vue.use(native) */
import utils from '@/utils'
Vue.use(utils)
import emitter from '@/utils/emitter'
Vue.mixin(emitter)

import { DevConfig, nativeHandler } from 'qmp-native'
Vue.prototype.$nativeHandler = nativeHandler
window.nativeHandler = nativeHandler
if (process.env.NODE_ENV !== 'production') {
  // web测试环境调试配置
  DevConfig.useDefaultData = !(process.env.NODE_ENV === 'production')
  DevConfig.defaultData = {
    '': {
      token: `bearer ${getCookieToken()}`
    },
    // nativeHandler('getBaseInfo') 接口在测试环境返回的数据
    'getBaseInfo': {
      account: 'testAccount',
      userName: '暂代',
      photo: 'https://testimg.quanyou.com.cn/group1/M00/01/05/rB8Mk1_AWuSAVt9tAAFObr6LJgs389.png',
      appRoleDTOList: [
        {
          roleCode: '1606553685790',
          roleDesc: null,
          roleId: '0573339d-d215-4194-b333-9dd21531941a',
          roleName: '2023年会权限角色1'
        }
      ]
    },
    // 调用原生其他接口 返回的数据
    'default': {
      'property1': 'value1',
      'property2': 'value2'
    },
    appRoleDTOList: [
      {
        roleCode: '1606553685790',
        roleDesc: null,
        roleId: 'ec2edf20-6854-4472-aedf-20685404729c',
        roleName: 'SAD后台管理员'
      },
      {
        roleCode: '1595933457788',
        roleDesc: null,
        roleId: '0867c49b-338d-4348-a7c4-9b338d434877',
        roleName: 'CTM-客户经理角色1'
      }
    ]
  }
}

Vue.config.productionTip = false

Vue.use(Vant)
Vue.component('svg-icon', SvgIcon)
sync(store, router)

Vue.mixin({
  beforeRouteLeave: function(to, from, next) {
    // const toIndex = window.sessionStorage.getItem(to.path)
    // const fromIndex = from ? window.sessionStorage.getItem(from.path) : '-1'
    // if (from && toIndex && fromIndex && fromIndex > toIndex) { // 此处判断是如果返回上一层，你可以根据自己的业务更改此处的判断逻辑，酌情决定是否摧毁本层缓存。
    //   if (this.$vnode && this.$vnode.data.keepAlive) {
    //     if (this.$vnode.parent && this.$vnode.parent.componentInstance && this.$vnode.parent.componentInstance.cache) {
    //       if (this.$vnode.componentOptions) {
    //         var key = this.$vnode.key == null
    //           ? this.$vnode.componentOptions.Ctor.cid + (this.$vnode.componentOptions.tag ? `::${this.$vnode.componentOptions.tag}` : '')
    //           : this.$vnode.key
    //         var cache = this.$vnode.parent.componentInstance.cache
    //         var keys = this.$vnode.parent.componentInstance.keys
    //         if (cache[key]) {
    //           if (keys.length) {
    //             var index = keys.indexOf(key)
    //             if (index > -1) {
    //               keys.splice(index, 1)
    //             }
    //           }
    //           delete cache[key]
    //         }
    //       }
    //     }
    //   }
    //   this.$destroy()
    // }
    next()
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
